package site.teamo.biu.net.client.controller;

import jakarta.annotation.Resource;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import site.teamo.biu.net.client.controller.model.server_management.Server;
import site.teamo.biu.net.client.service.ServerManagementService;
import site.teamo.biu.tool.core.model.BiuJSONResult;
import site.teamo.biu.tool.core.util.BiuJSONResultUtils;

import java.util.List;

/**
 * @author haocongshun
 * @date 2023/06/07 15:55:31
 */
@RestController
@RequestMapping("/api/server-management")
public class ServerManagementController {

    @Resource(name = "serverManagementServiceImpl")
    private ServerManagementService serverManagementService;

    @PostMapping(value = "/access", consumes = MediaType.TEXT_PLAIN_VALUE)
    public BiuJSONResult<Boolean> access(@RequestBody String accessUrl) {
        boolean access = serverManagementService.access(accessUrl);
        return BiuJSONResultUtils.ok(access);
    }

    @GetMapping("/query")
    public BiuJSONResult<List<Server>> queryServiceNodes() {
        return BiuJSONResultUtils.ok(serverManagementService.queryServers());
    }


    @PostMapping("/delete")
    public BiuJSONResult<Boolean> delete(@RequestParam String id) {
        return BiuJSONResultUtils.ok(serverManagementService.delete(id));
    }
}
